﻿// 获取当前日期时间
var now = new Date();
var year = now.getFullYear();
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var day = ("0" + now.getDate()).slice(-2);
var hours = ("0" + now.getHours()).slice(-2);
var minutes = ("0" + now.getMinutes()).slice(-2);
//var seconds = ("0" + now.getSeconds()).slice(-2);
var serialNumber =   year +"-" +month+"-" + day ;
var inputElement = document.getElementById('CreatedTimess');
inputElement.value = serialNumber;
var image = "";


layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var upload = layui.upload;
    var layer = layui.layer;
    var element = layui.element;
    var $ = layui.$;
    var table = layui.table;
    var dropdown = layui.dropdown;
     var form = layui.form;
    var laypage = layui.laypage;
  // 单图片上传
    // 获取从视图中嵌入的 ApiUrl
    var apiUrl = $('#apiUrl').data('url');

    var uploadInst = upload.render({
        elem: '#ID-upload-demo-btn',
        url: apiUrl+'yuan/api/Ingredient/Upfile', // 实际使用时改成您自己的上传接口即可。
        before: function (obj) {
            // 预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#ID-upload-demo-img').attr('src', result); // 图片链接（base64）
            });

            element.progress('filter-demo', '0%'); // 进度条复位
            layer.msg('上传中', { icon: 16, time: 0 });
        },
        done: function (res) {
            image=res.data
            console.log(res.data)
            // 若上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            // 上传成功的一些操作
            // …
            $('#ID-upload-demo-text').html(''); // 置空上传失败的状态
        },
        error: function () {
            // 演示失败状态，并实现重传
            var demoText = $('#ID-upload-demo-text');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        },
        // 进度条
        progress: function (n, elem, e) {
            element.progress('filter-demo', n + '%'); // 可配合 layui 进度条元素使用
            if (n == 100) {
                layer.msg('上传完毕', { icon: 1 });
            }
        }
    });
    var image = "";
    window.DeviceAdd = function DeviceAdd() {
        Ingredientnumber = $("#Ingredientnumber").val(),
        IngredientName = $("#IngredientName").val(),
            IngredientFen = $("#IngredientFen").val(),
            size = $("#size").val(),
            specification = $("#specification").val(),
            Rawmaterialproperties = $("#Rawmaterialproperties").val(),
            unit = $("#unit").val(),
            Num = $("#Num").val(),
            IngredientType = $("#IngredientType").val(),
            State = $("[name='State']:checked").val(),
            IngredientNum = $("#IngredientNum").val(),
            alarmDays = $("#alarmDays").val(),
            InventoryLimit = $("#InventoryLimit").val(),
            InventoryMinimum = $("#InventoryMinimum").val(),
            Rawmateriallocation = $("#Rawmateriallocation").val(),
            CreatedTimess = $("#CreatedTimess").val(),
            remark = $("#remark").val(),
            console.log(CreatedTimess)
            images = image,
            PickingId = "",
        PickingNum = ""
       $.ajax({
            url: '../Ingredient/IngredientAdd',
            type: 'post',
           data: {
               Ingredientnumber:Ingredientnumber,
               IngredientName:IngredientName,
               IngredientFen:IngredientFen ,
               size:size,
               specification:specification,
               Rawmaterialproperties:Rawmaterialproperties,
               unit:unit ,
               Num: Num ,
               IngredientType:IngredientType ,
               State: State,
               IngredientNum:IngredientNum ,
               alarmDays:alarmDays,
               InventoryLimit:InventoryLimit,
               InventoryMinimum:InventoryMinimum,
               Rawmateriallocation:Rawmateriallocation,
               CreatedTimess: CreatedTimess,
               remark:remark,
               images:images,
               PickingId:PickingId,
               PickingNum: PickingNum,
               token:""
              
            },
            //contentType: 'application/json',
            success: function (res) {
                console.log(res)
                var res = JSON.parse(res)
                if (res.data > 0) {
                    alert("添加成功")
                    window.location.href = '/Ingredient/ShowIngredient'
                }
                else {
                    alert("添加失败")
                }

            }
        })

    }







});